--
-- Author: shunguo.chen
-- Date: 2018-05-09 20:00:27
--
-- GuideFeatureView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.GuideFeatureScene

function ClassRef:init()
	display.uiAddClick(self._ui.Panel, function()
		executeFunc(self._onCloseView, self)
	end)
end

-- conf = featureon表功能配置
function ClassRef:refresh(conf)
	local class = UD:getClass()
	local iconTp = tonumber(conf.iconType or 1)
	local iconName = conf.bubbleIcon
	if string.isContain(iconName, ";") then
		local _, _, value = string.find(iconName .. ";", class .. "|(.-);")
		iconName = value
	end

	local panel = self._ui["Panel/Panel_img"]

	-- timeline
	local aniNode = cc.CSLoader:createNode(Res.GuideFeatureEfcNodes[iconTp])
	aniNode:setPosition(panel:getChildByName("animation"):getPosition())
	panel:addChild(aniNode, -1)
	local timeline = aniNode:getTimeline()
	timeline:play("animation0", false)

	local info = timeline:getAnimationInfo("animation0")
	local duration = info.endIndex - info.startIndex
	aniNode:performWithDelay(function()
			timeline:play("animation1", true)
		end, duration * app:getAnimationInterval())

	-- particle
	self._ui.flash_01:resetSystem()

	panel:getChildByName("img_s"):setVisible(false)
	local icon
	if iconTp == 1 then
		icon = panel:getChildByName("img_b")
	elseif iconTp == 2 then
		icon = panel:getChildByName("img_m")
	else
		icon = panel:getChildByName("img_s")
	end
	icon:setVisible(true)
	icon:loadTexture(string.format(Res.GuideFeatureIconPath, iconName))

	local bbName = L(conf.bubbleName)
	if conf.bubbleType then
		-- 1-技能
		-- 2-装备
		-- 3-专精
		local bbType = conf.bubbleType
		local bbValue = conf.bubbleValue
		if string.isContain(bbValue, ";") then
			local _, _, value = string.find(bbValue .. ";", class .. "|(.-);")
			bbValue = value
		end

		local secIcon
		local path
		if bbType == "1" then
			local skillConf = GD:getClassSkill(bbValue)
			bbName = bbName .. ": " .. L(skillConf.name)

			secIcon = panel:findChild("img_s/skill_icon")
			path = string.format("art/skill_icon/%s.png", skillConf.icon)
		elseif bbType == "2" then
			local equipConf = GD:getEquipConf(bbValue)
			bbName = bbName .. ": " .. L(equipConf.string)

			secIcon = panel:findChild("img_s/arms_icon")
			path = string.format(Res.GuideFeatureIconPath, bbValue)
		elseif bbType == "3" then
			local skillConf = GD:getSpec_typeConfig(bbValue)
			bbName = bbName .. ": " .. L(skillConf.nameDes)
		end

		if secIcon and path then
			secIcon:setVisible(true)
			secIcon:loadTexture(path)
		end
	end

	self._ui.tlt:setString(bbName)
	self._ui.text:setString(L(conf.bubbleDesc))
end

return ClassRef
